<?php
	class dynamic_widget extends Widget 
	{
		public function display($args)
		{
			//print_r($args);
			//$CI =& get_instance();
			if($args['widget_type']=="gallery")
			{
				$widgets=$this->general_model->select_val("galleries","*","short_name = '".$args['short_name']."'");	
			}
			else if($args['widget_type']=="slider")
			{
				$widgets=$this->general_model->select_val("sliders","*","short_name = '".$args['short_name']."'");
			}
			else
			{
				$widgets=$this->general_model->select_val("widgets","*","short_name = '".$args['short_name']."'");
			}
			//print_r($widgets);
			switch($widgets['widget_type'])
			{
				case "video":
					$data['widgets']=$this->embedded_video->get_video(strip_tags($widgets['widget_content']),array('height'=>$widgets['widget_height']==0 ? 300 : $widgets['widget_height'] ,'width'=>$widgets['widget_width']==0 ? 400 : $widgets['widget_width']));
					break;
				case "custom":
					$data['widgets']=stripslashes($widgets['widget_content']);
					break;
				case "gallery":
					$shortdata = '<link href="'.base_url().'assets/front/css/lightbox.css" rel="stylesheet" />';
					$shortdata .= '<script src="'.base_url().'assets/front/js/lightbox-2.6.min.js"></script>';
					$this->template->javascript->add('lightbox');
					$shortdata.='<div class="image-row">';
					$shortdata.=	'<div class="image-set">';
					$allimages = $this->general_model->select("gallery_images","*","gallery_id = '".$widgets['id']."'");
						
					foreach($allimages as $images)
					{
						$shortdata.=		'<a class="example-image-link" href="'.base_url('assets/uploads/images').'/'.$images['filename'].'" data-lightbox="example-set" title="Click on the right side of the image to move forward."><img class="example-image" src="'.base_url('assets/uploads/images').'/'.$images['filename'].'" alt="Plants: image 1 0f 4 thumb" width="150" height="150"/></a>';
					}
					$shortdata.=	'</div>';
					$shortdata.='</div>';
					$data['widgets']=$shortdata;
					break;
				case "slider":
					
					$sliderhtml='<script src="'.base_url().'assets/front/js/jquery.nivo.slider.js"></script>';
					$sliderhtml .= '<link href="'.base_url().'assets/front/css/nivo-slider.css" rel="stylesheet" />';
					$sliderhtml.="<script>$(window).load(function() {
						$('#slider').nivoSlider(
							{
							 prevText: ' ',
							 nextText: ' ',
							 controlNav: false,
							}
						);
					});</script>";
					$sliderhtml.='<div id="slider" class="nivoSlider">';
					$allimages = $this->general_model->select("slider_images","*","slider_id = '".$widgets['id']."' order by sort ASC ");
					
					foreach($allimages as $images)
					{
						$sliderhtml.='<img src="'.base_url('assets/uploads/images').'/'.$images['filename'].'" />';
					}
					$sliderhtml.='</div>';
					$data['widgets']=$sliderhtml;
					break;
				default:
					$data['widgets']="";
			}
			
			$this->load->view('widgets/customwidget', $data);	
		}
	}
?>